package com.hz.monitoring.module.hardware.convert.monitoring_warning_log;

import java.util.*;

import com.hz.monitoring.framework.common.pojo.PageResult;

import com.hz.monitoring.framework.common.util.json.JsonUtils;
import com.hz.monitoring.module.hardware.controller.admin.monitoring_warning_log.vo.*;
import com.hz.monitoring.module.hardware.controller.admin.vo.CustomWarningAttribute;
import com.hz.monitoring.module.hardware.dal.dataobject.monitoring_warning_log.MonitoringWarningLogDO;
import org.springframework.util.StringUtils;

/**
 * 预警日志 Convert
 *
 * @author 芋道源码
 */
public class MonitoringWarningLogConvert {
    public static MonitoringWarningLogDO convert(MonitoringWarningLogCreateReqVO bean) {
        if ( bean == null ) {
            return null;
        }

        String warningMetadata = null;
        if (Objects.nonNull(bean.getWarningMetadata())) {
            warningMetadata = JsonUtils.toJsonString(bean.getWarningMetadata());
        }

        MonitoringWarningLogDO monitoringWarningLogDO = new MonitoringWarningLogDO();

        monitoringWarningLogDO.setTenantId( bean.getTenantId() );
        monitoringWarningLogDO.setSensorTenantResourceId( bean.getSensorTenantResourceId() );
        monitoringWarningLogDO.setMcuTenantResourceId( bean.getMcuTenantResourceId() );
        monitoringWarningLogDO.setWarningMetadata( warningMetadata );
        monitoringWarningLogDO.setMonitoringValue( bean.getMonitoringValue() );
        monitoringWarningLogDO.setLogTemplate( bean.getLogTemplate() );

        return monitoringWarningLogDO;
    }

   
    public static MonitoringWarningLogDO convert(MonitoringWarningLogUpdateReqVO bean) {
        if ( bean == null ) {
            return null;
        }
        String warningMetadata = null;
        if (Objects.nonNull(bean.getWarningMetadata())) {
            warningMetadata = JsonUtils.toJsonString(bean.getWarningMetadata());
        }

        MonitoringWarningLogDO monitoringWarningLogDO = new MonitoringWarningLogDO();

        monitoringWarningLogDO.setTenantId( bean.getTenantId() );
        monitoringWarningLogDO.setId( bean.getId() );
        monitoringWarningLogDO.setSensorTenantResourceId( bean.getSensorTenantResourceId() );
        monitoringWarningLogDO.setMcuTenantResourceId( bean.getMcuTenantResourceId() );
        monitoringWarningLogDO.setWarningMetadata(warningMetadata);
        monitoringWarningLogDO.setMonitoringValue( bean.getMonitoringValue() );
        monitoringWarningLogDO.setLogTemplate( bean.getLogTemplate() );

        return monitoringWarningLogDO;
    }

   
    public static MonitoringWarningLogRespVO convert(MonitoringWarningLogDO bean) {
        if ( bean == null ) {
            return null;
        }
        CustomWarningAttribute warningMetadata = null;
        if (StringUtils.hasLength(bean.getWarningMetadata())) {
            warningMetadata = JsonUtils.parseObject(bean.getWarningMetadata(), CustomWarningAttribute.class);
        }
        MonitoringWarningLogRespVO monitoringWarningLogRespVO = new MonitoringWarningLogRespVO();

        monitoringWarningLogRespVO.setSensorTenantResourceId( bean.getSensorTenantResourceId() );
        monitoringWarningLogRespVO.setMcuTenantResourceId( bean.getMcuTenantResourceId() );
        monitoringWarningLogRespVO.setWarningMetadata(warningMetadata);
        monitoringWarningLogRespVO.setMonitoringValue( bean.getMonitoringValue() );
        monitoringWarningLogRespVO.setLogTemplate( bean.getLogTemplate() );
        monitoringWarningLogRespVO.setTenantId( bean.getTenantId() );
        monitoringWarningLogRespVO.setId( bean.getId() );
        monitoringWarningLogRespVO.setCreateTime( bean.getCreateTime() );

        return monitoringWarningLogRespVO;
    }

   
    public static List<MonitoringWarningLogRespVO> convertList(List<MonitoringWarningLogDO> list) {
        if ( list == null ) {
            return null;
        }

        List<MonitoringWarningLogRespVO> list1 = new ArrayList<MonitoringWarningLogRespVO>( list.size() );
        for ( MonitoringWarningLogDO monitoringWarningLogDO : list ) {
            list1.add( convert( monitoringWarningLogDO ) );
        }

        return list1;
    }

   
    public static PageResult<MonitoringWarningLogRespVO> convertPage(PageResult<MonitoringWarningLogDO> page) {
        if ( page == null ) {
            return null;
        }

        PageResult<MonitoringWarningLogRespVO> pageResult = new PageResult<MonitoringWarningLogRespVO>();

        pageResult.setList( convertList( page.getList() ) );
        pageResult.setTotal( page.getTotal() );

        return pageResult;
    }

   
    public static List<MonitoringWarningLogExcelVO> convertList02(List<MonitoringWarningLogDO> list) {
        if ( list == null ) {
            return null;
        }

        List<MonitoringWarningLogExcelVO> list1 = new ArrayList<MonitoringWarningLogExcelVO>( list.size() );
        for ( MonitoringWarningLogDO monitoringWarningLogDO : list ) {
            list1.add( monitoringWarningLogDOToMonitoringWarningLogExcelVO( monitoringWarningLogDO ) );
        }

        return list1;
    }

    protected static MonitoringWarningLogExcelVO monitoringWarningLogDOToMonitoringWarningLogExcelVO(MonitoringWarningLogDO monitoringWarningLogDO) {
        if ( monitoringWarningLogDO == null ) {
            return null;
        }

        MonitoringWarningLogExcelVO monitoringWarningLogExcelVO = new MonitoringWarningLogExcelVO();

        monitoringWarningLogExcelVO.setId( monitoringWarningLogDO.getId() );
        monitoringWarningLogExcelVO.setSensorTenantResourceId( monitoringWarningLogDO.getSensorTenantResourceId() );
        monitoringWarningLogExcelVO.setMcuTenantResourceId( monitoringWarningLogDO.getMcuTenantResourceId() );
        monitoringWarningLogExcelVO.setWarningMetadata( monitoringWarningLogDO.getWarningMetadata() );
        monitoringWarningLogExcelVO.setMonitoringValue( monitoringWarningLogDO.getMonitoringValue() );
        monitoringWarningLogExcelVO.setLogTemplate( monitoringWarningLogDO.getLogTemplate() );
        monitoringWarningLogExcelVO.setCreateTime( monitoringWarningLogDO.getCreateTime() );

        return monitoringWarningLogExcelVO;
    }
}
